

package com.loong.loong.hik.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.loong.loong.common.core.util.R;
import com.loong.loong.common.log.annotation.SysLog;
import com.loong.loong.hik.entity.HikCdcSmartMeter;
import com.loong.loong.hik.service.HikCdcSmartMeterService;
import org.springframework.security.access.prepost.PreAuthorize;
import com.loong.loong.common.excel.annotation.ResponseExcel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 智能电表
 *
 * @author dxy
 * @date 2023-04-12 15:30:06
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/hikcdcsmartmeter" )
@Api(value = "hikcdcsmartmeter", tags = "智能电表管理")
public class HikCdcSmartMeterController {

    private final  HikCdcSmartMeterService hikCdcSmartMeterService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param hikCdcSmartMeter 智能电表
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page" )
    @PreAuthorize("@pms.hasPermission('hik_hikcdcsmartmeter_view')" )
    public R getHikCdcSmartMeterPage(Page page, HikCdcSmartMeter hikCdcSmartMeter) {
        return R.ok(hikCdcSmartMeterService.page(page, Wrappers.query(hikCdcSmartMeter)));
    }


    /**
     * 通过id查询智能电表
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('hik_hikcdcsmartmeter_view')" )
    public R getById(@PathVariable("id" ) Integer id) {
        return R.ok(hikCdcSmartMeterService.getById(id));
    }

    /**
     * 新增智能电表
     * @param hikCdcSmartMeter 智能电表
     * @return R
     */
    @ApiOperation(value = "新增智能电表", notes = "新增智能电表")
    @SysLog("新增智能电表" )
    @PostMapping
    @PreAuthorize("@pms.hasPermission('hik_hikcdcsmartmeter_add')" )
    public R save(@RequestBody HikCdcSmartMeter hikCdcSmartMeter) {
        return R.ok(hikCdcSmartMeterService.save(hikCdcSmartMeter));
    }

    /**
     * 修改智能电表
     * @param hikCdcSmartMeter 智能电表
     * @return R
     */
    @ApiOperation(value = "修改智能电表", notes = "修改智能电表")
    @SysLog("修改智能电表" )
    @PutMapping
    @PreAuthorize("@pms.hasPermission('hik_hikcdcsmartmeter_edit')" )
    public R updateById(@RequestBody HikCdcSmartMeter hikCdcSmartMeter) {
        return R.ok(hikCdcSmartMeterService.updateById(hikCdcSmartMeter));
    }

    /**
     * 通过id删除智能电表
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id删除智能电表", notes = "通过id删除智能电表")
    @SysLog("通过id删除智能电表" )
    @DeleteMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('hik_hikcdcsmartmeter_del')" )
    public R removeById(@PathVariable Integer id) {
        return R.ok(hikCdcSmartMeterService.removeById(id));
    }


    /**
     * 导出excel 表格
     * @param hikCdcSmartMeter 查询条件
     * @return excel 文件流
     */
    @ResponseExcel
    @GetMapping("/export")
    @PreAuthorize("@pms.hasPermission('hik_hikcdcsmartmeter_export')" )
    public List<HikCdcSmartMeter> export(HikCdcSmartMeter hikCdcSmartMeter) {
        return hikCdcSmartMeterService.list(Wrappers.query(hikCdcSmartMeter));
    }
}
